//
//  SalePlolyVC.m
//  WestAir
//
//  Created by s on 16/9/25.
//  Copyright © 2016年 Henry. All rights reserved.
//

#import "SalePlolyVC.h"

@interface SalePlolyVC ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *btnHasRead;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewHeight;
@property (weak, nonatomic) IBOutlet UIView *viewBG;

@end

@implementation SalePlolyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self  initDataAndUI];
    
}

-(void)initDataAndUI{
    
    VIEW_CORNER(_btnHasRead, buttonCorner21);
    _btnHasRead.backgroundColor=NORMAL_BULUE_COLOR;
    VIEW_CORNER(self.viewBG, 4.0);
    _textView.editable=NO;
    
    HangBanInfo  *hangBanInfo=[HangBanInfo  currentHangBan];
    NSString  *FFLIGHTNUMBER=hangBanInfo.FFLIGHTNUMBER;
    NSString  *FFLIGHTDATE=hangBanInfo.FFLIGHTDATE;
    
    
    NSDictionary  *dicParama=@{@"FNUMBER":FFLIGHTNUMBER,@"FFLIGHTDATE":FFLIGHTDATE};
    NSDictionary  *dicJson= [CMCCIOTIGUnity   getRequestJson:dicParama];
    
    [[NetworkFactory  alloc]  startPostRequestWithURL:SALPOLICIES andPostValues:dicJson andSuccessBlock:^(NSDictionary *responseJson) {
        
        if ([responseJson[@"IsSuccess"]  integerValue]==1) {
        
         NSString  *strContent=responseJson[@"SalPolicies"];
           
            if (strContent.length) {
                
                
                CGSize  sizeHeight=[CMCCIOTIGUnity  getSize:strContent andSize:CGSizeMake(self.textView.widthV, MAXFLOAT) and:self.textView.font];
                self.textView.text=strContent;
                self.viewHeight.constant=sizeHeight.height+30;
                
                
                float  heightMax=(SCREEN_HEIGHT-180);
                
                if ([[MemberList  currentUsinfo].FREADSALEPOLICY  isEqualToString:@"1"]) {
                    heightMax=(SCREEN_HEIGHT-110);
                }
                
                if (sizeHeight.height+30>heightMax) {
                    self.viewHeight.constant=heightMax;
                    _textView.scrollEnabled=YES;
                }
                
            
            }
            else{
            
                self.viewHeight.constant=50;
                self.textView.text=@"暂无内容";
            }
         
            
        }
        else{
           
             self.viewHeight.constant=50;
             self.textView.text=@"暂无内容";
        }
        
        
        
    } andFailBlock:^(NSError *error) {
       
         self.viewHeight.constant=50;
        self.textView.text=@"暂无内容";
        
    } ];
    
    if ([[MemberList  currentUsinfo].FREADSALEPOLICY  isEqualToString:@"1"]) {
        _btnHasRead.hidden=YES;
    }

}
- (IBAction)popBack:(id)sender {
    
    [self.navigationController  popViewControllerAnimated:YES];
    
}
- (IBAction)salePolyRead:(id)sender {
    
    MemberList  *currentMember=[MemberList currentUsinfo];
    
    NSDictionary  *dicParama=@{@"FEntryID":[NSNumber numberWithInteger:currentMember.FEntryID]};
    NSDictionary  *dicJson= [CMCCIOTIGUnity   getRequestJson:dicParama];
    
    [[NetworkFactory  alloc]  startPostRequestWithURL: SETREADSALEPOLICY andPostValues:dicJson andSuccessBlock:^(NSDictionary *responseJson) {
        
        if ([responseJson[@"IsSuccess"]  integerValue]==1) {
            
            [MemberList currentUsinfo].FREADSALEPOLICY=@"1";
            [self.navigationController  popViewControllerAnimated:YES];
            
        }
        else{
           [self.navigationController  popViewControllerAnimated:YES];

        }
        
    } andFailBlock:^(NSError *error) {
    
        [self.navigationController  popViewControllerAnimated:YES];
    } ];

   
   
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
